Core.Action.Dom = function(struct, type) {
	Core.Action.Dom.superclass.constructor.call(this, struct);
	
	this.node;
	this.attrs = struct.properties();
	this.createNode(type);
	this.createContent();
	
	this.attached = false;
};

Env.extend(Core.Action.Dom, Core.Action.Abstract, {
	
	createNode: function(type) {
		var map, node = this.node = document.createElement(type),
		
		map = this.attrs.attrs;
		for(var k in map) {
			node.setAttribute(k, map[k]);
		}
		
		map = this.attrs.styles;
		for(var k in map) {
			node.style[k] = map[k];
		}
		
		map = this.attrs.events;
		for(var k in map) {
			Event.attach(k, map[k], node, attrs);
		}
	},
	
	attach: function(parent, before) {
		Core.assert(parent instanceof Core.Action.Dom, "Parent action is not Core.Action.Dom instance");
		Core.assert(!before || before instanceof Core.Action.Dom, "After action is not Core.Action.Dom instance")
		
		if(before && before.isAttached()) { parent.node.insertBefore(this.node, before.node); }
		else { parent.node.appendChild(this.node); }
		
		this.attached = true;
	},
	
	isAttached: function() {
		return this.attached;
	},
	
	detach: function() {
		this.node.parentNode.removeChild(this.node);
		this.attached = false;
	}
});
